using System.Collections.Generic;

//
// * Copyright (c) 2002-2010 "Neo Technology,"
// *     Network Engine for Objects in Lund AB [http://neotechnology.com]
// *
// * This file is part of Neo4j.
// * 
// * Neo4j is free software: you can redistribute it and/or modify
// * it under the terms of the GNU Affero General Public License as
// * published by the Free Software Foundation, either version 3 of the
// * License, or (at your option) any later version.
// * 
// * This program is distributed in the hope that it will be useful,
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// * GNU Affero General Public License for more details.
// * 
// * You should have received a copy of the GNU Affero General Public License
// * along with this program. If not, see <http://www.gnu.org/licenses/>.
// 
namespace org.neo4j.kernel
{


	using GraphDatabaseService = org.neo4j.graphdb.GraphDatabaseService;
	using Node = org.neo4j.graphdb.Node;
	using Relationship = org.neo4j.graphdb.Relationship;
	using RelationshipType = org.neo4j.graphdb.RelationshipType;
	using Transaction = org.neo4j.graphdb.Transaction;
	using TransactionFailureException = org.neo4j.kernel.impl.transaction.TransactionFailureException;

///
/// <summary> * A read-only version of <seealso cref="EmbeddedGraphDatabase"/>. </summary>
/// 
	public sealed class EmbeddedReadOnlyGraphDatabase : GraphDatabaseService
	{
		private static Map<string, string> readOnlyParams = new Dictionary<string, string>();

		static EmbeddedReadOnlyGraphDatabase()
		{
			readOnlyParams.put("read_only", "true");
		}

		private readonly EmbeddedGraphDbImpl neoImpl;

///    
///     <summary> * Creates an embedded <seealso cref="GraphDatabaseService"/> with a store located in
///     * <code>storeDir</code>. If the directory shouldn't exist or isn't a neo4j
///     * store an exception will be thrown.
///     *  </summary>
///     * <param name="storeDir"> the store directory for the Neo4j store files </param>
///     
		public EmbeddedReadOnlyGraphDatabase(string storeDir) : this(storeDir, readOnlyParams)
		{
		}

///    
///     <summary> * A non-standard way of creating an embedded <seealso cref="GraphDatabaseService"/>
///     * with a set of configuration parameters. Will most likely be removed in
///     * future releases.
///     * <p>
///     * Creates an embedded <seealso cref="GraphDatabaseService"/> with a store located in
///     * <code>storeDir</code>. If the directory shouldn't exist or isn't a neo4j
///     * store an exception will be thrown.
///     *  </summary>
///     * <param name="storeDir"> the store directory for the db files </param>
///     * <param name="params"> configuration parameters </param>
///     
		public EmbeddedReadOnlyGraphDatabase(string storeDir, Map<string, string> @params)
		{
			@params.put("read_only", "true");
			this.neoImpl = new EmbeddedGraphDbImpl(storeDir, @params, this);
		}

///    
///     <summary> * A non-standard convenience method that loads a standard property file and
///     * converts it into a generic <Code>Map<String,String></CODE>. Will most
///     * likely be removed in future releases.
///     *  </summary>
///     * <param name="file"> the property file to load </param>
///     * <returns> a map containing the properties from the file </returns>
///     
		public static Map<string, string> loadConfigurations(string file)
		{
			return EmbeddedGraphDbImpl.loadConfigurations(file);
		}

		public Node createNode()
		{
			return neoImpl.createNode();
		}

		public Node getNodeById(long id)
		{
			return neoImpl.getNodeById(id);
		}

		public Relationship getRelationshipById(long id)
		{
			return neoImpl.getRelationshipById(id);
		}

		public Node getReferenceNode()
		{
			return neoImpl.getReferenceNode();
		}

		public void shutdown()
		{
			neoImpl.shutdown();
		}

		public bool enableRemoteShell()
		{
			return neoImpl.enableRemoteShell();
		}

//JAVA TO VB & C# CONVERTER WARNING: 'final' parameters are not allowed in .NET:
//ORIGINAL LINE: public boolean enableRemoteShell(final Map<String, Serializable> initialProperties)
		public bool enableRemoteShell(Map<string, Serializable> initialProperties)
		{
			return neoImpl.enableRemoteShell(initialProperties);
		}

		public IEnumerable <RelationshipType> getRelationshipTypes()
		{
			return neoImpl.getRelationshipTypes();
		}

///    
///     * <exception cref="TransactionFailureException"> if unable to start transaction </exception>
///     
		public Transaction beginTx()
		{
			return neoImpl.beginTx();
		}

///    
///     <summary> * Returns a non-standard configuration object. Will most likely be removed
///     * in future releases.
///     *  </summary>
///     * <returns> a configuration object </returns>
///     
		public Config getConfig()
		{
			return neoImpl.getConfig();
		}

		public override string ToString()
		{
			return base.ToString() + " [" + neoImpl.getStoreDir() + "]";
		}

		public string getStoreDir()
		{
			return neoImpl.getStoreDir();
		}

		public IEnumerable <Node> getAllNodes()
		{
			return neoImpl.getAllNodes();
		}
	}

}